from django.db import models
from main.models import BaseModel


class {{ModelName}}(BaseModel):
    {% set type_map={'varchar':'models.CharField','int':'models.IntegerField',
                'text':'models.TextField','datetime':'models.DateTimeField'} %}
    {% for item in FieldList %}
    {{item['field_name']}} = {{type_map[item['field_type']]}}(
        "{{item['field_desc']}}",
        {% if item['field_type'] == 'varchar' %}
        max_length={{item['field_length']}}, 
        {% endif %}
        {% if item['field_index'] == 'index' %}
        db_index=True,                
        {% endif %}
        {% if item['field_index'] == 'unique' %}
        unique=True,                
        {% endif %}
        blank=True,
        default={{item['field_length']}},
        null={{item['field_null']}},
        )
    {% endfor %}

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = "{{ModelName}}"
        verbose_name_plural = verbose_name
